package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Attacked;
import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Sign;
import com.myk.game.heroscuffle.game.Skill;
import com.myk.game.heroscuffle.skills.Skill_PoXiang;
import com.myk.game.heroscuffle.utils.RdmPropUtil;

public class Hero_XiaoYin extends Hero {

    public final int ADD_DAMAGE_UNIT = 5; //目标每损失100点hp的伤害增加量

    public Hero_XiaoYin() {
        super("肖隐",
                "必定服从玩家指定。普通攻击对低生命值的目标造成更高的伤害。免疫所有技能和标记伤害。", Element.DARK,
                1250, 150, 50,
                new Skill_PoXiang());
    }

    @Override
    public void onAcceptPlayerAttackAction(Attacked preAttacked) {
        preAttacked.setReason("未等话落,剑已刺向");
        this.doAttackActionStart(preAttacked); //始终尊从指定
    }

    @Override
    public void onAutoSelectAction() {
        if (game.pool.getAliveCount() > 2) {
            Skill_PoXiang poxiang = (Skill_PoXiang) getUsableSkill(Skill_PoXiang.class);
            Attacked attacked = super.autoSelectAttacked();
            if (poxiang != null) {
                if (attacked.getTarget() instanceof Hero_ShuiQing) { //羁绊，遇到水清就直接使用poxiang
                    poxiang.setIntentTarget(attacked.getTarget());
                    useSkill(poxiang);
                }
                else {
                    if (attacked.getTarget().atk > 150) { //对攻击力高的敌人提高使用poxiang的概率
                        if (RdmPropUtil.bingo(1 / 2d)) {
                            poxiang.setIntentTarget(attacked.getTarget());
                            useSkill(poxiang);
                        }
                        else {
                            attacked.setReason("神情冷漠,飘忽快斩");
                            doAttackActionStart(attacked);
                        }
                    }
                    else {
                        if (RdmPropUtil.bingo(1 / 3d)) {
                            poxiang.setIntentTarget(attacked.getTarget());
                            useSkill(poxiang);
                        }
                        else {
                            attacked.setReason("神情冷漠,飘忽快斩");
                            doAttackActionStart(attacked);
                        }
                    }
                }
            }
            else { //没有技能
                attacked.setReason("无忧无惧,挥剑横扫");
                doAttackActionStart(attacked);
            }
        }
        else { //只剩下一个敌人，敌人不得不打我，再用poxiang就傻了
            Attacked attacked = super.autoSelectAttacked();
            attacked.setReason("无念无想,瞬影直刺");
            doAttackActionStart(attacked);
        }
    }

    @Override
    public void onBeforeDoAttack(Hero attacked) {
        if (attacked.hp < attacked.HP / 2) { //对半血以下的敌人造成额外伤害
            int multiple = (attacked.HP - attacked.hp) / 100;
            int atkAdd = multiple * ADD_DAMAGE_UNIT;
            game.ui.printMsg(getObviousName() + "atk临时增加" + atkAdd + "点，");
            atk += atkAdd;
            event.onAfterDoAttack.addRunBack(eventData -> {
                atk -= atkAdd;
                eventData.removeRunBackFromListener();
            });
        }
        attacked.beAttackActionStart(this); //重写记得回调此方法以继续流程
    }

    @Override
    public void onAfterSufferDamage(Hero attacker, Skill sourceSkill, Sign sourceSign, int damage) {
        if (sourceSkill != null || sourceSign != null) { //免疫技能和标记伤害。
            hp += damage;
            game.ui.printMsg(getObviousName() + "免疫了该伤害,");
            game.ui.sleepShortly();
        }
    }
}
